<?php

namespace app\models\user;

use Yii;

/**
 * This is the model class for table "user_level".
 *
 * @property int $id
 * @property string $name 身份名称
 * @property string|null $display 前端显示名称
 * @property string $key 身份查询标识,英文
 * @property int $value 身份查询标识,数值
 * @property string $create_time
 * @property string $update_time
 * @property float $performance 累计业绩
 * @property int $push_num 直推数量
 * @property string $push_level 直推等级
 * @property string|null $desc 身份说明
 */
class UserLevel extends \yii\db\ActiveRecord
{
    public static $keys = [

        'none' => 0,

        'vip1' => 101,
        'vip2' => 102,

        'svip1' => 201,
        'svip2' => 202,
        'svip3' => 203,


    ];

    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'user_level';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['name'], 'required'],
            [['value', 'push_num'], 'integer'],
            [['create_time', 'update_time'], 'safe'],
            [['performance'], 'number'],
            [['desc'], 'string'],
            [['name', 'display', 'key', 'push_level'], 'string', 'max' => 255],

            [['hide'], 'safe'],
            [['ops', 'store'], 'safe'],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'name' => 'Name',
            'display' => 'Display',
            'key' => 'Key',
            'value' => 'Value',
            'create_time' => 'Create Time',
            'update_time' => 'Update Time',
            'performance' => 'Performance',
            'push_num' => 'Push Num',
            'push_level' => 'Push Level',
            'desc' => 'Desc',
        ];
    }

    public static function getKey($value)
    {
        foreach (self::$keys as $k => $v) {
            if ($v == $value) {
                return $k;
            }
        }

        return  '';
    }
}
